<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  

  
  <title>地藏思维</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="分享互联网各类技术场景、开发中间件">
<meta property="og:type" content="website">
<meta property="og:title" content="地藏思维">
<meta property="og:url" content="https://kelvin-cai.gitee.io/dizang-blog/index.html">
<meta property="og:site_name" content="地藏思维">
<meta property="og:description" content="分享互联网各类技术场景、开发中间件">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="Kelvin">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/dizang-blog/atom.xml" title="地藏思维" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  
<link rel="stylesheet" href="/dizang-blog/css/style.css">

<meta name="generator" content="Hexo 5.2.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/dizang-blog/" id="logo">地藏思维</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/dizang-blog/">Home</a>
        
          <a class="main-nav-link" href="/dizang-blog/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/dizang-blog/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="搜索"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="https://kelvin-cai.gitee.io/dizang-blog"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main">
  
    <article id="post-《SpringCloudDubbo开发日记》（一）Nacos连官方文档都没写好" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/dizang-blog/2020/09/29/%E3%80%8ASpringCloudDubbo%E5%BC%80%E5%8F%91%E6%97%A5%E8%AE%B0%E3%80%8B%EF%BC%88%E4%B8%80%EF%BC%89Nacos%E8%BF%9E%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E9%83%BD%E6%B2%A1%E5%86%99%E5%A5%BD/" class="article-date">
  <time datetime="2020-09-29T02:19:47.000Z" itemprop="datePublished">2020-09-29</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/dizang-blog/2020/09/29/%E3%80%8ASpringCloudDubbo%E5%BC%80%E5%8F%91%E6%97%A5%E8%AE%B0%E3%80%8B%EF%BC%88%E4%B8%80%EF%BC%89Nacos%E8%BF%9E%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E9%83%BD%E6%B2%A1%E5%86%99%E5%A5%BD/">《SpringCloudDubbo开发日记》（一）Nacos连官方文档都没写好</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h1 id="背景"><a href="#背景" class="headerlink" title="背景"></a>背景</h1><p>现在的微服务框架一般分dubbo和springcloud两套服务治理体系，dubbo是基于zookeeper为注册中心，springcloud是基于eureka作为注册中心。</p>
<p>但是现在eureka作为注册中心停止更新了，只有维护状态。并且netfix体系的feign和hystrix也是停止更新了，官方都开始推荐其他的代替方案。eureka这套体系也挺好用的，比较兼顾SpringMvc开发习惯，也辉煌了4个年头，尽力了。</p>
<p>本章节会讲述我在部署Nacos遇到的坑点，后续把SpringCloudAlibaba体系不为人知的坑给告诉大家。</p>
<p>最近在做商城项目，前后端都是自己开发，所以用一套最新的后端技术栈。<br>springcloud官方文档也把springCloud alibaba放在了文档，而且alibaba放弃zookeeper作为注册中心，并且把dubbo捡起来作为服务调用，所以后续开发新项目打算使用新的微服务治理体系及其周边配套。</p>
<table>
<thead>
<tr>
<th>指标</th>
<th>服务治理与发现</th>
<th>RPC远程调用方式</th>
<th>服务配置</th>
<th>定时任务调度</th>
<th>消息通信</th>
<th>前端</th>
<th>网关</th>
</tr>
</thead>
<tbody><tr>
<td>技术组件</td>
<td>Nacos</td>
<td>Dubbo的rpc</td>
<td>Nacos</td>
<td>Xschedule</td>
<td>RocketMq</td>
<td>VUE、UNIAPP</td>
<td>dubbo服务发现+url中转方式</td>
</tr>
</tbody></table>
        
          <p class="article-more-link">
            <a href="/dizang-blog/2020/09/29/%E3%80%8ASpringCloudDubbo%E5%BC%80%E5%8F%91%E6%97%A5%E8%AE%B0%E3%80%8B%EF%BC%88%E4%B8%80%EF%BC%89Nacos%E8%BF%9E%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E9%83%BD%E6%B2%A1%E5%86%99%E5%A5%BD/#more">Read More</a>
          </p>
        
      
    </div>
    <footer class="article-footer">
      <a data-url="https://kelvin-cai.gitee.io/dizang-blog/2020/09/29/%E3%80%8ASpringCloudDubbo%E5%BC%80%E5%8F%91%E6%97%A5%E8%AE%B0%E3%80%8B%EF%BC%88%E4%B8%80%EF%BC%89Nacos%E8%BF%9E%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E9%83%BD%E6%B2%A1%E5%86%99%E5%A5%BD/" data-id="ckfnc6n4000006coo1v9ofbsw" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-动态生成简约MVC请求接口抛弃一切注解减少重复劳动吧" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/dizang-blog/2020/09/28/%E5%8A%A8%E6%80%81%E7%94%9F%E6%88%90%E7%AE%80%E7%BA%A6MVC%E8%AF%B7%E6%B1%82%E6%8E%A5%E5%8F%A3%E6%8A%9B%E5%BC%83%E4%B8%80%E5%88%87%E6%B3%A8%E8%A7%A3%E5%87%8F%E5%B0%91%E9%87%8D%E5%A4%8D%E5%8A%B3%E5%8A%A8%E5%90%A7/" class="article-date">
  <time datetime="2020-09-28T03:37:06.000Z" itemprop="datePublished">2020-09-28</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/dizang-blog/2020/09/28/%E5%8A%A8%E6%80%81%E7%94%9F%E6%88%90%E7%AE%80%E7%BA%A6MVC%E8%AF%B7%E6%B1%82%E6%8E%A5%E5%8F%A3%E6%8A%9B%E5%BC%83%E4%B8%80%E5%88%87%E6%B3%A8%E8%A7%A3%E5%87%8F%E5%B0%91%E9%87%8D%E5%A4%8D%E5%8A%B3%E5%8A%A8%E5%90%A7/">动态生成简约MVC请求接口|抛弃一切注解减少重复劳动吧</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h1 id="背景"><a href="#背景" class="headerlink" title="背景"></a>背景</h1><p>目前创建一个后端请求接口给别人提供服务，无论是使用SpringMVC方式注解，还是使用SpringCloud的Feign注解，都是需要填写好@RequestMap、@Controller、@Pathvariable等注解和参数。每个接口都需要重复的劳动，非常繁琐。特别是服务治理框架的接口层不是springmvc，而都是通过TCP连接来做RPC通信的接口，这样的接口调试起来比较麻烦，测试人员也不能感知接口参数，压力测试的时候没得使用JMETER方便。</p>
<h1 id="目的"><a href="#目的" class="headerlink" title="目的"></a>目的</h1><p>为了解放双手，让后端服务开发人员提供接口给别人时，只需要更关注逻辑。减少开发人员关注框架内容，减少关注每个@注解上的参数信息，不用再校验path是否已经被使用过。无须再感知SpringMVC或者Feign的存在。</p>
<p>我们统一做处理，把类名和方法名来做为请求接口url，不再显式声明url，默认POST请求、返回为JSON形式，请求参数支持@RequestBody、@RequestParam。</p>
<blockquote>
<p>点赞再看，关注公众号：【地藏思维】给大家分享互联网场景设计与架构设计方案<br>掘金：地藏Kelvin <a target="_blank" rel="noopener" href="https://juejin.im/user/1046390801444615">https://juejin.im/user/1046390801444615</a></p>
</blockquote>
        
          <p class="article-more-link">
            <a href="/dizang-blog/2020/09/28/%E5%8A%A8%E6%80%81%E7%94%9F%E6%88%90%E7%AE%80%E7%BA%A6MVC%E8%AF%B7%E6%B1%82%E6%8E%A5%E5%8F%A3%E6%8A%9B%E5%BC%83%E4%B8%80%E5%88%87%E6%B3%A8%E8%A7%A3%E5%87%8F%E5%B0%91%E9%87%8D%E5%A4%8D%E5%8A%B3%E5%8A%A8%E5%90%A7/#more">Read More</a>
          </p>
        
      
    </div>
    <footer class="article-footer">
      <a data-url="https://kelvin-cai.gitee.io/dizang-blog/2020/09/28/%E5%8A%A8%E6%80%81%E7%94%9F%E6%88%90%E7%AE%80%E7%BA%A6MVC%E8%AF%B7%E6%B1%82%E6%8E%A5%E5%8F%A3%E6%8A%9B%E5%BC%83%E4%B8%80%E5%88%87%E6%B3%A8%E8%A7%A3%E5%87%8F%E5%B0%91%E9%87%8D%E5%A4%8D%E5%8A%B3%E5%8A%A8%E5%90%A7/" data-id="ckfnc6n4800026coodgl833d5" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-主键生成器效率提升方案基于雪花算法和Redis控制进程隔离" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/dizang-blog/2020/09/28/%E4%B8%BB%E9%94%AE%E7%94%9F%E6%88%90%E5%99%A8%E6%95%88%E7%8E%87%E6%8F%90%E5%8D%87%E6%96%B9%E6%A1%88%E5%9F%BA%E4%BA%8E%E9%9B%AA%E8%8A%B1%E7%AE%97%E6%B3%95%E5%92%8CRedis%E6%8E%A7%E5%88%B6%E8%BF%9B%E7%A8%8B%E9%9A%94%E7%A6%BB/" class="article-date">
  <time datetime="2020-09-28T02:37:06.000Z" itemprop="datePublished">2020-09-28</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/dizang-blog/2020/09/28/%E4%B8%BB%E9%94%AE%E7%94%9F%E6%88%90%E5%99%A8%E6%95%88%E7%8E%87%E6%8F%90%E5%8D%87%E6%96%B9%E6%A1%88%E5%9F%BA%E4%BA%8E%E9%9B%AA%E8%8A%B1%E7%AE%97%E6%B3%95%E5%92%8CRedis%E6%8E%A7%E5%88%B6%E8%BF%9B%E7%A8%8B%E9%9A%94%E7%A6%BB/">主键生成器效率提升方案|基于雪花算法和Redis控制进程隔离</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h1 id="背景"><a href="#背景" class="headerlink" title="背景"></a>背景</h1><ol>
<li>主键生成效率用数据库自增效率也是比较高的，为什么要用主键生成器呢？是因为需要insert主表和明细表时，明细表有个字段是主表的主键作为关联。所以就需要先生成主键填好主表明细表的信息后再一次过在一个事务内插入。或者是产生支付流水号时要全局唯一，所以要先生成后插入，不能靠数据库主键。</li>
<li>网上有很多主键生成器方式，其中有算法部分和实现部分。算法部分一般就是雪花算法或者以业务编号前缀+年月日形式。</li>
<li>一般算法设计没有问题，而在实现方案上，只是同学利用Redis很多实现起来的都是不高效的，他们没考虑Redis都是单线程的情况下多个同时请求生成会有等待的时间。下面我们来对比2款实现方式，看看他们的问题点在哪里，还有我的改进实现方案。</li>
</ol>
<h1 id="目的"><a href="#目的" class="headerlink" title="目的"></a>目的</h1><ol>
<li>减少网络连接Redis的次数，来减少TCP次数。</li>
<li>减少因Redis的单线程串行造成的等待</li>
<li>两个进程、docker或者说两个服务器之间隔离</li>
<li>减少Redis内存使用率</li>
</ol>
<blockquote>
<p>点赞再看，关注公众号：【地藏思维】给大家分享互联网场景设计与架构设计方案<br>掘金：地藏Kelvin <a target="_blank" rel="noopener" href="https://juejin.im/user/1046390801444615">https://juejin.im/user/1046390801444615</a></p>
</blockquote>
<h1 id="最终实现工具"><a href="#最终实现工具" class="headerlink" title="最终实现工具"></a>最终实现工具</h1><ol>
<li>Redis： incr、get、set以达到控制进程隔离</li>
<li>只连接一次Redis</li>
<li>LUA脚本保持原子</li>
<li>syncronize</li>
<li>雪花算法以达到不重复键</li>
</ol>
        
          <p class="article-more-link">
            <a href="/dizang-blog/2020/09/28/%E4%B8%BB%E9%94%AE%E7%94%9F%E6%88%90%E5%99%A8%E6%95%88%E7%8E%87%E6%8F%90%E5%8D%87%E6%96%B9%E6%A1%88%E5%9F%BA%E4%BA%8E%E9%9B%AA%E8%8A%B1%E7%AE%97%E6%B3%95%E5%92%8CRedis%E6%8E%A7%E5%88%B6%E8%BF%9B%E7%A8%8B%E9%9A%94%E7%A6%BB/#more">Read More</a>
          </p>
        
      
    </div>
    <footer class="article-footer">
      <a data-url="https://kelvin-cai.gitee.io/dizang-blog/2020/09/28/%E4%B8%BB%E9%94%AE%E7%94%9F%E6%88%90%E5%99%A8%E6%95%88%E7%8E%87%E6%8F%90%E5%8D%87%E6%96%B9%E6%A1%88%E5%9F%BA%E4%BA%8E%E9%9B%AA%E8%8A%B1%E7%AE%97%E6%B3%95%E5%92%8CRedis%E6%8E%A7%E5%88%B6%E8%BF%9B%E7%A8%8B%E9%9A%94%E7%A6%BB/" data-id="ckfnc6n4700016coog39u5swo" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  


</section>
        
          <aside id="sidebar">
  
    

  
    

  
    
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">归档</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/dizang-blog/archives/2020/09/">九月 2020</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/dizang-blog/2020/09/29/%E3%80%8ASpringCloudDubbo%E5%BC%80%E5%8F%91%E6%97%A5%E8%AE%B0%E3%80%8B%EF%BC%88%E4%B8%80%EF%BC%89Nacos%E8%BF%9E%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E9%83%BD%E6%B2%A1%E5%86%99%E5%A5%BD/">《SpringCloudDubbo开发日记》（一）Nacos连官方文档都没写好</a>
          </li>
        
          <li>
            <a href="/dizang-blog/2020/09/28/%E5%8A%A8%E6%80%81%E7%94%9F%E6%88%90%E7%AE%80%E7%BA%A6MVC%E8%AF%B7%E6%B1%82%E6%8E%A5%E5%8F%A3%E6%8A%9B%E5%BC%83%E4%B8%80%E5%88%87%E6%B3%A8%E8%A7%A3%E5%87%8F%E5%B0%91%E9%87%8D%E5%A4%8D%E5%8A%B3%E5%8A%A8%E5%90%A7/">动态生成简约MVC请求接口|抛弃一切注解减少重复劳动吧</a>
          </li>
        
          <li>
            <a href="/dizang-blog/2020/09/28/%E4%B8%BB%E9%94%AE%E7%94%9F%E6%88%90%E5%99%A8%E6%95%88%E7%8E%87%E6%8F%90%E5%8D%87%E6%96%B9%E6%A1%88%E5%9F%BA%E4%BA%8E%E9%9B%AA%E8%8A%B1%E7%AE%97%E6%B3%95%E5%92%8CRedis%E6%8E%A7%E5%88%B6%E8%BF%9B%E7%A8%8B%E9%9A%94%E7%A6%BB/">主键生成器效率提升方案|基于雪花算法和Redis控制进程隔离</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2020 Kelvin<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/dizang-blog/" class="mobile-nav-link">Home</a>
  
    <a href="/dizang-blog/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  
<link rel="stylesheet" href="/dizang-blog/fancybox/jquery.fancybox.css">

  
<script src="/dizang-blog/fancybox/jquery.fancybox.pack.js"></script>




<script src="/dizang-blog/js/script.js"></script>




  </div>
</body>
</html>